## Install InfluxDB at first
## Set up the InfluxDB with organization and initial bucket
## Log in the InfluxDB UI and get the token
## Configure the output plugin influxdb_v2 with these datas
[[outputs.influxdb_v2]]
  urls = ["https://127.0.0.1/influxdb"]
  token = "Fk9bfXNidCehkfbkwjM2PL7eRuwHWmwLAoHE8DRFhaZr4K2SvYpALKSkj0Rs2ScSgtlbUfXmVGPBtR8BK_GpJQ=="
  organization = "Bosch Rexroth"
  bucket = "ctrlX_Telegraf"
  insecure_skip_verify = true

## Configure the input plugin with the username and password to ctrlX Core  
[[inputs.ctrlx_datalayer_sse]]
   ## Hostname or IP address of ctrlX CORE
   ##  example: hostname = "localhost"        # Telegraf is running directly on the device
   ##           hostname = "192.168.1.1"      # Connect to ctrlX CORE remote via IP
   ##           hostname = "host.example.com" # Connect to ctrlX CORE remote via hostname
   ##           hostname = "10.0.2.2:8443"    # Connect to ctrlX CORE Virtual from development environment
   hostname = "localhost"

   ## Authentication credentials
   username = "boschrexroth"
   password = "boschrexroth"

   ## Use TLS but skip chain & host verification
   insecure_skip_verify = true

   ## Timeout for HTTP requests. (default: "10s")
   # timeout = "10s"

   ## Create a ctrlX Data Layer SSE subscription.
   ## It is possible to define multiple subscriptions per host. Each subscription can have its own
   ## sampling properties and a list of nodes to subscribe to.
   ## All subscriptions share the same credentials.
   [[inputs.ctrlx_datalayer_sse.subscription]]
      ## The name of the measurement. (default: "ctrlx")
      measurement = "metrics"

      ## Define an array of nodes with field name and node address
      ## name - field name to use in the output (optional, default: "value_{type}")
      ## address - node address in ctrlX Data Layer
      ## Example:
      ## {name="counter", address="scheduler/admin/info/counter"}
      nodes=[
         {name="cpu_usage_percent", address="framework/metrics/system/cpu-utilisation-percent"},
         {name="mem_used_mb", address="framework/metrics/system/memused-mb"}
      ]

      ## The switch "output_json_string" determines the format of the output metric. (default: false)
      ## false: the default output format is used with the following conversion rule:
      ##  - simple types (bool8,int8,uint8,int16,uint16,int32,uint32,int64,uint64,float,double,string,timestamp): 
      ##    pass the value as it ist to a metric with pattern '{name}={value}'
      ##  - array types (arbool8,arint8,aruint8,arint16,aruint16,arint32,aruint32,arint64,aruint64,arfloat,ardouble,arstring,artimestamp): 
      ##    pass every value in the array to a metric with pattern '{name_index}={value[index]}'
      ##    example: myarray=[1,2,3] -> myarray_1=1, myarray_2=2, myarray_3=3
      ##  - object types (json types): 
      ##    use a json flattener and pass every flattened value to a metric with pattern '{name}_{jsonflat.key}={jsonflat.value}'
      ##    example: myobj = {"a":1,"b":2,"c":{"d": 3}} -> myobj_a=1, myobj_b=2, myobj_c_d=3
      ## true: the output value is formatted to json string
      ##    pass the value as json string to a metric with pattern '{name}="{value}"'
      ##    examples: 
      ##      input = true -> output = "true"
      ##      input = [1,2,3] -> output = "[1,2,3]"
      ##      input = {"x":4720,"y":9440,"z":{"d": 14160}} -> output = "{\"x\":4720,\"y\":9440,\"z\":14160}"
      ##    output json string can be used for further processing e.g. starlark.
      ##    see: https://docs.influxdata.com/telegraf/v1.23/plugins/#processor-plugins
      ##    example:
      ##      [[inputs.ctrlx_datalayer_sse.subscription]]
      ##      measurement = "osci"
      ##      nodes = [
      ##        {address="oscilloscope/instances/Osci_PLC/rec-values/allsignals"},
      ##      ]
      ##      output_json_string = true
      ##      [[processors.starlark]]
      ##      namepass = [
      ##         'osci',
      ##      ]
      ##      script = "oscilloscope.star"
      # output_json_string = false

      ## Define extra tags related to subscription to be added to the output metric (optional)
      # [inputs.ctrlx_datalayer_sse.subscription.tags]
      #    machine = "impresser"
      #    location = "main building"

      ## The interval in which messages shall be sent by the ctrlX Data Layer to this plugin. (default: 1s)
      ## Higher values reduce load on network by queuing samples on server side and sending as a single TCP packet.
      # publish_interval = "1s"

      ## The interval a "keepalive" message is sent if no change of data occurs. (default: 60s)
      ## Only used internally to detect broken network connections.
      # keep_alive_interval = "60s"

      ## The interval an "error" message is sent if an error was received from a node. (default: 10s)
      ## Higher values reduce load on output target and network in case of errors by limiting frequency of error messages.
      # error_interval = "20s"

      ## The interval that defines the fastest rate at which the node values should be sampled and values captured. (default: 1s)
      ## The sampling frequency should be adjusted to the dynamics of the signal to be sampled.
      ## Higher sampling frequence increases load on ctrlX Data Layer.
      ## The sampling frequency can be higher, than the publish interval. Captured samples are put in a queue and sent in publish interval.
      ## Note: The minimum sampling interval can be overruled by a global setting in the ctrlX Data Layer configuration ('datalayer/subscriptions/settings').
       sampling_interval = "100ms"

      ## The requested size of the node value queue. (default: 10)
      ## Relevant if more values are captured than can be sent.
      # queue_size = 10

      ## The behaviour of the queue if it is full. (default: "DiscardOldest")
      ## Possible values: 
      ## - "DiscardOldest"
      ##   The oldest value gets deleted from the queue when it is full.
      ## - "DiscardNewest"
      ##   The newest value gets deleted from the queue when it is full.
      # queue_behaviour = "DiscardOldest"

      ## The filter when a new value will be sampled. (default: 0.0)
      ## Calculation rule: If (abs(lastCapturedValue - newValue) > dead_band_value) capture(newValue).
      # dead_band_value = 0.0

      ## The conditions on which a sample should be captured and thus will be sent as a message. (default: "StatusValue")
      ## Possible values:
      ## - "Status"
      ##   Capture the value only, when the state of the node changes from or to error state. Value changes are ignored.
      ## - "StatusValue" 
      ##   Capture when the value changes or the node changes from or to error state.
      ##   See also 'dead_band_value' for what is considered as a value change.
      ## - "StatusValueTimestamp": 
      ##   Capture even if the value is the same, but the timestamp of the value is newer.
      ##   Note: This might lead to high load on the network because every sample will be sent as a message
      ##   even if the value of the node did not change.
      # value_change = "StatusValue"
